package org.jiaxin.nutrient.utils;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author jiaxin
 * @version 1.0
 * @description: TODO
 * @date 2024/1/6 10:54
 */
public class RegionUtils {
    private final HashMap<String, String> map = new HashMap<String, String>();

    public RegionUtils() throws Exception {
        String fileContentFromLocalPath = FileUtils.getFileContentFromLocalPath("src/main/resources/region.json");
        Pattern pattern = Pattern.compile("\"value\":\\s*(\\d+),\\s*\"label\":\\s*\"(.*?)\"");
        Matcher matcher = pattern.matcher(fileContentFromLocalPath);
        while (matcher.find()) {
            String value = matcher.group(1);
            String label = matcher.group(2);
            map.put(value,label);
        }
    }

    public  String transRegionCodeToName(String regionCode) throws Exception {
        return map.get(regionCode);
    }
}
